package Lambda;

public class LambdaFun {

    public void insideFun(double aa,double bb){
        System.out.println("insideFun Start");

        //标准写法
        funAdd f1=(double a,double b)->{
            System.out.println(""+a+"和"+b+"的"+"和为："+(a+b));
            return a+b;
        };
        f1.fun(aa,bb);

        //精简写法，忽略形参类型
        funSub f2=(a,b)->{
            System.out.println(""+a+"和"+b+"的"+"差为：" + (a-b));
            return a-b;
        };
        f2.fun(aa,bb);

        //再精简写法，单形参可以忽略形参类型和括号
        funSqu f3=a -> {
            System.out.println(a+"的平方数为："+(a*a));
            return a*a;
        };
        f3.fun(aa);

        //单语句可以忽略花括号
        funDiv f4=(a,b)-> System.out.println(""+a+"和"+b+"的"+"商为"+(a/b));
        f4.fun(aa,bb);

        //只有一句return的话，可以忽略花括号和return
        funMul f5=(a,b)->a*b;
        System.out.println(""+aa+"和"+bb+"的积为"+f5.fun(aa,bb));

        System.out.println("insideFun End");
    }

    public void outsideFun(double a,double b){
        System.out.println("outsideFun Start");

        LambdaFun fun = new LambdaFun();
        funAdd fa=fun::funAdd01;
        fa.fun(a,b);

        System.out.println("outsideFun End");
    }

    public double funAdd01(double a,double b){
        System.out.println(""+a+"和"+b+"的"+"和为："+(a+b));
        return a+b;
    }

    interface funAdd{
        double fun(double a,double b);
    }

    interface funSub{
        double fun(double a,double b);
    }

    interface funSqu{
        double fun(double a);
    }

    interface funMul{
        double fun(double a,double b);
    }

    interface funDiv{
        void fun(double a,double b);
    }

}
